<?php
require ROOT_PATH.'/Helper/front_abstract.php';
require ROOT_PATH.'/Helper/yzm.php';

class Action extends front_abstract
{
    function index()
    {
	if(Request::isPost()){
		
	    $info= _POST('info' ,array());
	    
	    if(empty($info['email'])){

		$this->msg('Email填写不完整!');	    
	    }

	    if(empty($info['password'])){

		$this->msg('密码填写不完整!');	    
	    }
	    
	    
    	    if (filter_var($info['email'], FILTER_VALIDATE_EMAIL) === false) {

    		    $user_info= _model('user')->read(array('name'=>$info['email'],'password'=>md5($info['password'])));
		    if($user_info){
			    	    
				    $_SESSION['user']=$user_info;
					
				    $this->redirect('index.html');
			    
			    
		    }else{	    		
			    $this->msg('账号或密码错误!');
		    }
	
    	    }else {
    
		    $user_info= _model('user')->read(array('email'=>$info['email'],'password'=>md5($info['password'])));	    			
		    if($user_info){
			    	
			    $_SESSION['user']=$user_info;
			    $this->redirect('index.html');
			    
		    }else{
			    $this->msg('账号或密码错误!');
		    }
	   }
		
	} else {
		

		if(empty($_SESSION['user'])){

			$this->view->display('front/login.html');
		}else{

			$this->redirect('index.html');
		}
	}
    	
    }

	
    function reforget(){
   
  		$this->view->display('front/reforget.html'); 
    }

    function ck_reforget(){
    
	    $info = _POST('info',array());

	    if (filter_var($info['email'], FILTER_VALIDATE_EMAIL) === false) {

		  $this->msg('请填写正确的邮箱!'); 	
	    }else{
		    
		    if(empty($info['email'])){
		    
			    $this->msg('邮箱不能为空!');
		    }	

	   	 if($info['conf_code']!=$_SESSION['verify']){
		    
			    $this->msg('验证码错误!');
		    }

		    $check= _model('user')->read(array('email'=>$info['email']));
	   
	    if($check){

		 $check['password'] = substr($check['password'], 0, 10);
	    
		$this->send_email($info['email'],'通知：密码修改',"<a href='".SITE_URL."./login/forget?email=".$check['email']."&pass=".$check['password']."'>请点击修改密码!</a>");
		    $this->msg('密码修复邮件已发送到您的邮箱中!', 'login/index');
	    		
	    }else{
	    
	    		$this->msg('邮箱错误!','login/reforget');
	    }

	}
    }

    

		
    function forget(){
		
	    $email = _GET('email');

	    $pass = _GET('pass');

	    $data= _model('user')->read(array('email'=>$email));
	    
	    $password=substr($data['password'], 0, 10);

	 
	    if($data){
	    	
		     if($pass == $password){	

			    $this->view->assign('email', $email);
			    $this->view->display('front/forget.html');		  	
		     }else{
				
			     $this->msg('非法操作!!!','index.html');
		     }
	    }else{
	    
	    
	    		$this->msg('非法操作!','index.html');
	    }

	     
    }	

    function findout(){
    

	    $info = _POST('info', array());

	    if($info['conf_code']!=$_SESSION['verify']){
		    
		    $this->msg('验证码错误!');
	    }
	  
	    if($info['password']!=$info['re_password']){
	    	$this->msg('两次密码不一致');
	    }

	    if($info){
	    
		$insert = array();
		if(!empty($info['password'])){
			$insert['password'] = md5($info['password']);
		}		
	    	_model('user')->update(array('email'=>$info['email']), $insert);
	    	$this->msg('修改成功','login/index');
    	
    		
	     }else{
	     
	     	$this->msg('修改失败!');
	     }
 
    }


    function yzm(){

	    
	    $yz=yzm();
	    header("Cache-Control: no-cache, must-revalidate");
	    $_SESSION['verify']=strtolower($yz);
	    
			
    }


  
}
?>
